package com.ruoyi.system.domain.video;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.util.BeanUtils;
import com.ruoyi.system.mapper.video.VsLangTranslateMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Map;
/**
 * 自用的工具类
 */
public class JsonToDB {

    @Autowired
    private static VsLangTranslateMapper vsLangTranslateMapper;

    public static void main(String[] args) {


        try (BufferedReader reader = new BufferedReader(new FileReader("C:\\\\Users\\\\32022\\\\Desktop\\\\zh-Hans.json"))) {
            String line;
            StringBuilder sb = new StringBuilder();
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
            String jsonContent = sb.toString();
            // 将 JSON 字符串转换为 JSON 对象

            Map<String,Object> map = (Map<String, Object>) JSON.parseObject(jsonContent);
            for (Map.Entry<String, Object> entry : map.entrySet()) {
                VsLangTranslate v = new VsLangTranslate();
                String key = entry.getKey();
                String value = (String) entry.getValue();
                v.setKeyCode(key);
                v.setChinese(value);
                v.setLanguage(value);
                vsLangTranslateMapper.insertVsLangTranslate(v);
            }
            System.out.println(map);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
